# -*- coding: utf-8 -*-

"""
* Copyright (C) 2016 GridSafe, Inc.
"""
from django.db import models
from django.contrib.auth.models import User


class statistic(models.Model):
    """
    个人资产
    """
    id = models.AutoField(primary_key=True)
    user = models.OneToOneField(User, db_index=True, help_text="绑定用户个人信息")
    pay = models.DecimalField(max_digits=10, decimal_places=2, help_text="用户支出")
    borrow = models.DecimalField(max_digits=10, decimal_places=2, help_text='欠款')

    income = models.DecimalField(max_digits=10, decimal_places=2, help_text="用户收入信息")
    description = models.CharField(max_length=255, null=True, blank=True, help_text='备注')
    created_datetime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'statistic'


class statisticLog(models.Model):
    """"""
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=50, help_text='标题')
    money = models.DecimalField(max_digits=10, decimal_places=4)
    type = models.CharField(max_length=50)
    created_datetime = models.DateTimeField(auto_now=True)
    updated_datetime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'statistic_log'


class StatisticType(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20, db_index=True)
    description = models.CharField(max_length=20, null=True, blank=True)

    class Meta:
        db_table = 'StatisticType'


class IncomeTable(models.Model):
    """
    收入
    """
    id = models.AutoField(primary_key=True)
    user = models.OneToOneField(User, db_index=True)
    money = models.DecimalField(max_digits=10, decimal_places=2)
    type = models.ForeignKey(StatisticType)
    description = models.TextField(null=True, blank=True)
    created_datetime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Income'


class ExpenseTable(models.Model):
    """
    收入
    """
    id = models.AutoField(primary_key=True)
    user = models.OneToOneField(User, db_index=True)
    type = models.ForeignKey(StatisticType)
    money = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField(null=True, blank=True)
    created_datetime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Expend'
